package com.liudadan.aspect_02;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TransactionAspect {
    //通知 + 切入点
    //开启（前置） 提交（返回） 回滚（异常）
    /**
     *
     * try{
     *     前置：@Before
     *     目标方法
     *     返回：@AfterReturning
     * }catch(){
     *     异常：@AfterThrowing
     * }finally{
     *     后置：@After
     * }
     */
    @Before("com.liudadan.aspect_02.TransactionPointCut.pc()")
    public void begin(){
        System.out.println("开启事务");
    }
    @AfterReturning("com.liudadan.aspect_02.TransactionPointCut.pc()")
    public void commit(){
        System.out.println("提交事务");
    }
    @AfterThrowing("com.liudadan.aspect_02.TransactionPointCut.pc()")
    public void rollback(){
        System.out.println("回滚事务");
    }
}
